< previous page page_375 next page >

Page 375
Private properties are used only internally by the object itself. Internally, a form may hold other data, such as the window style and the parent who owns the window. This is data that you cannot see or change but is still part of the form class.
Here are some examples of public properties:
9f31265bb40b592b1929e18a47ab28e5.gif
frmEmployee.Top = 10
txtFirstName.Text = "Bill"
Methods
Methods are procedures or functions defined by a class. These snippets of code can only be invoked through a corresponding object thats created as that type of class. Methods are typically used to change something about the object or tell the object to perform some action. Lets use an example from some built-in objects in Visual Basic. Heres an example:
9f31265bb40b592b1929e18a47ab28e5.gif
frmEmployee.Move 100, 100
This line of code moves the frmEmployee form to a specified location on the screen. The Move method is part of the Window class, upon which a Visual Basic form is based. Some programmer wrote source code to make a form object move. Another example would be to use the common dialog control, like this:
9f31265bb40b592b1929e18a47ab28e5.gif
dlgCommon.ShowOpen
In this example, youre telling an object to perform some action on itself. The message youre sending to this object is to show its Open dialog box. The common dialog control knows how to perform this action. In fact, if you were to look at the ShowOpen method, you would see that all it does is perform some Windows API calls, which you could actually do yourself from Visual Basic. The big difference here is that you simply need to remember one method instead of all the parameters and declarations needed to make the Windows API calls.
Encapsulation
Encapsulation is another word for data hiding. The concept of data hiding has been around since the beginning of programming. Most programmers strive to create black-box routines, which are passed some data, perform some operation, and maybe pass something back. You dont know how the routine performs the operation, you only know that the data you receive is correct. In other words, the functionality has been encapsulated in this routine. In OOP, you encapsulate properties (data) and methods (subroutines) into a single class file.

 
< previous page page_375 next page >

If you like this book, buy it!